package com.cby.springboot.demo.service;

import com.cby.springboot.demo.bean.AdminRolePermission;
import com.cby.springboot.demo.mapper.AdminRolePermissionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("adminRolePermissionService")
public class AdminRolePermissionServiceImpl implements AdminRolePermissionService{

    @Autowired
    AdminRolePermissionMapper mapper;

    @Override
    public List<AdminRolePermission> findAll() {
        return mapper.findAll();
    }

    @Override
    public List<AdminRolePermission> findByRid(int rid) {
        return mapper.findByRid(rid);
    }

    @Override
    public List<AdminRolePermission> findByPid(int pid) {
        return mapper.findByPid(pid);
    }

    @Override
    public List<AdminRolePermission> findAllByRid(List<Integer> rids) {
        int size = rids == null ? 0 : rids.size();
        List<AdminRolePermission> results = new ArrayList<>();
        if(size > 0) {
            for (int i = 0; i < size; i++) {
                results.addAll(findByRid(rids.get(i)));
            }
        }
        return results;
    }

    @Override
    public List<AdminRolePermission> findAllByPid(List<Integer> pids) {
        int size = pids == null ? 0 : pids.size();
        List<AdminRolePermission> results = new ArrayList<>();
        if(size > 0) {
            for (int i = 0; i < size; i++) {
                results.addAll(findByPid(pids.get(i)));
            }
        }
        return results;
    }
}
